package com.base.myproject.server.ratify;

import java.util.Vector;

public class RatifyObject {

	public java.util.LinkedList<RatifyObject> ll = new java.util.LinkedList<RatifyObject>();

	public String name = null;

	public String tobcode, status, tostatus, fromstatus, path = null;
	String tobcodeimg = null;
	String ratifycode;//业务编码
	String busiinnercode;//单据内码
	String code;//标识，审批单元的唯一标志
	//RatifyObject upratifycode;
	Vector<RatifyObject> upv = new Vector<RatifyObject>();
	Vector<RatifyObject> downv = new Vector<RatifyObject>();// 下游数据
	Vector<String> downvstr = new Vector<String>();// 下游数据 只装代码，
	boolean isfollow = false;// 是否打开审批表示，true则可以审批
	boolean isfirst = false;
	int ratifyflag=0;
	
	public final static int RATIFY=1; //同意
	public final static int RATIFY_FALSE=2;//反对
	public final static int RATIFY_WAITING=4;//保留意见
	public final static int RATIFY_CANCEL=8;//取消
	
	int	 ratifymode; //审批模式
	
	public final static int SINGLE=1; //单审
	public final static int UNION=2; //会审

	public RatifyObject(String ratifycode,String busiinnercode) {
		this.ratifycode = ratifycode;
		this.busiinnercode = busiinnercode;
	}

	public RatifyObject(String tobcode, String tostatus, String fromstatus) {

		this.tobcode = tobcode;
		this.tostatus = tostatus;
		this.fromstatus = fromstatus;
		// this.path =tobcode;//
		// "<table><tr><td><img src=\"/images/base/man1.gif\" /></td><td>"+tobcode+"</td></tr></table>";
		this.tobcodeimg = "<table><tr><td><img src=\"/images/baseimage/ratify/user.png\" /></td></tr><tr><td>"
				+ tobcode + "</td></tr></table>";
		this.path = tobcodeimg;
	}

	/**
	 * 审批
	 * 
	 * @return
	 */
	public boolean ratify(int flag) {
		
		switch (flag) {
		case RATIFY:
			return ratify();
			
		case RATIFY_FALSE:
			return ratifyFalse();
			
		case RATIFY_WAITING:
			return ratifyWaiting();
			
		case RATIFY_CANCEL:
			return ratifyCancel();
			

		default:
			break;
		}
		
		return false;
	}
	/**
	 * 审批通过
	 * @return
	 */
	protected boolean ratify()
	{
		if (isfirst || isIsfollow()) {
			setStatus(tostatus);
			for (RatifyObject ro : downv) {
				ro.setIsfollow(true);
			}
		}
		ratifyflag = RATIFY;
		return false;
	}
	/**
	 * 审批不通过
	 * @return
	 */
	protected boolean ratifyFalse()
	{
		ratifyflag = RATIFY_FALSE;
		return true;
	}
/**
 * 审批保留意见
 * @return
 */

	protected boolean ratifyWaiting()
	{
		ratifyflag = RATIFY_WAITING;
		return false;
	}
	/**
	 * 取消审批
	 * @return
	 */
	protected boolean ratifyCancel()
	{
		ratifyflag = RATIFY_CANCEL;
		return true;
	}
	public String toString() {
		return "code="+code+" ratifycode=" + ratifycode + " tostatus=" + tostatus
				+ " isfollw=" + isfollow + " isfirst=" + isfirst+" ratifyflag="+ratifyflag+" downvstr="+downvstr;
	}

	/**
	 * 添加下游数据的代码
	 * @param ratifycode
	 */
	public void addRatifyDownCodeStr (String ratifycode)
	{
		downvstr.add(ratifycode);
	}
	public Vector<String> getRatifyDownCodeStr(){
		return downvstr;
	}
	/**
	 * @return the ratifyflag
	 */
	public int getRatifyflag() {
		return ratifyflag;
	}

	/**
	 * @param ratifyflag the ratifyflag to set
	 */
	public void setRatifyflag(int ratifyflag) {
		this.ratifyflag = ratifyflag;
	}

	/**
	 * @return the icode
	 */
	public String getIcode() {
		return code;
	}

	/**
	 * @param icode the icode to set
	 */
	public void setIcode(String icode) {
		this.code = icode;
	}

	/**
	 * @return the isfollow
	 */
	public boolean isIsfollow() {
		return isfollow;
	}

	/**
	 * @param isfollow
	 *            the isfollow to set
	 */
	public void setIsfollow(boolean isfollow) {
		this.isfollow = isfollow;
	}

	/**
	 * @return the isfirst
	 */
	public boolean isIsfirst() {
		return isfirst;
	}

	/**
	 * @param isfirst
	 *            the isfirst to set
	 */
	public void setIsfirst(boolean isfirst) {
		this.isfirst = isfirst;
	}

	/**
	 * icode一样这这两对象是相等的
	 */
	public boolean equals(Object o) {
		if (o == null || !(o instanceof RatifyObject))
			return false;
		if (this.getIcode().equals(((RatifyObject) o).getIcode()))
			return true;
		return false;
	}
/**
 * 添加下游审批
 * @param ro
 */
	public void addDownRatifyObject(RatifyObject ro) {
		downv.add(ro);
		ro.addUpRatifyObject(this);
	}
	/**
	 * 添加上游审批,只能内部调用，由addDownRatifyObject设置
	 * @param ro
	 */
	
	private void addUpRatifyObject(RatifyObject ro) {
		upv.add(ro);
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @param status
	 *            the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 * @return the ratifycode
	 */
	public String getRatifycode() {
		return ratifycode;
	}

	/**
	 * @param ratifycode
	 *            the ratifycode to set
	 */
	public void setRatifycode(String ratifycode) {
		this.ratifycode = ratifycode;
	}



	/**
	 * @return the busiinnercode
	 */
	public String getBusiinnercode() {
		return busiinnercode;
	}

	/**
	 * @param busiinnercode the busiinnercode to set
	 */
	public void setBusiinnercode(String busiinnercode) {
		this.busiinnercode = busiinnercode;
	}

	/**
	 * @return the upv
	 */
	public Vector<RatifyObject> getUpv() {
		return upv;
	}

	/**
	 * @param upv the upv to set
	 */
	public void setUpv(Vector<RatifyObject> upv) {
		this.upv = upv;
	}

	/**
	 * @return the downv
	 */
	public Vector<RatifyObject> getDownv() {
		return downv;
	}

	/**
	 * @param downv the downv to set
	 */
	public void setDownv(Vector<RatifyObject> downv) {
		this.downv = downv;
	}

	/**
	 * @return the ratifymode
	 */
	public int getRatifymode() {
		return ratifymode;
	}

	/**
	 * @param ratifymode the ratifymode to set
	 */
	public void setRatifymode(int ratifymode) {
		this.ratifymode = ratifymode;
	}

	public String getTobcodeimg() {
		return tobcodeimg;
	}

	public void setTobcodeimg(String tobcodeimg) {
		this.tobcodeimg = tobcodeimg;
	}

	public String getTobcode() {
		return tobcode;
	}

	public void setTobcode(String tobcode) {
		this.tobcode = tobcode;
	}

	public String getTostatus() {
		return tostatus;
	}

	public void setTostatus(String tostatus) {
		this.tostatus = tostatus;
	}

	public String getFromstatus() {
		return fromstatus;
	}

	public void setFromstatus(String fromstatus) {
		this.fromstatus = fromstatus;
	}

	public void setName(String name) {
		this.name = name;

	}

	public String getName() {
		return name;
	}

	public void add(RatifyObject ro) {
		ll.add(ro);
	}

	public java.util.LinkedList<RatifyObject> getLl() {
		return ll;
	}

	public void setLl(java.util.LinkedList<RatifyObject> ll) {
		this.ll = ll;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

}
